<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="favicon.ico" type="image/x-icon">
    <title>字典标注服务接口文档</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 20px;
        }
        h1, h3, h3, h4, h5 {
            color: #333;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #f4f4f4;
        }
        code {
            background-color: #f4f4f4;
            padding: 2px 4px;
            border-radius: 4px;
            font-family: Consolas, "Courier New", monospace;
        }
        #codeBlock {
            display: none;
            margin-top: 10px;
        }
        #toggleButton {
            background-color: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
        }
        #toggleButton:hover {
            background-color: #0056b3;
        }
        .round-button {
            width: 24px;
            height: 24px;
            border-radius: 50%;
            border: none;
            background-color: #007bff; 
            color: white;
            font-size: 18px;
            font-weight: bold;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: background-color 0.3s;
        }

        .round-button:hover {
            background-color: #0056b3;
            opacity: 0.5;
        }   
    </style>
</head>
<body>
<h1 style="text-align: center;">字典标注接口文档</h1>
<h2>1. 语句标注接口 <button class="round-button" onclick="toggleCodeBlock(this, 'api1')">+</button></h1>
<div id="api1" style="display: none;">
    <h3>1.1. 接口描述 <button class="round-button" onclick="toggleCodeBlock(this, 'desc1')">-</button></h3>
    <div id="desc1">
        <ul>
            <li>请求地址：<strong>/tag</strong></li>
            <li>请求方式: <strong>POST/GET</strong></li>
            <li>返回数据类型：<strong>application/json</strong></li>
            <li>用途：根据字典，对传入的语句进行标注，返回语句中的关键词对应的字典名称及词条</li>
        </ul>
    </div>

    <h3>1.2. 请求参数 <button class="round-button" onclick="toggleCodeBlock(this, 'params1')">+</button></h3>
    <div id="params1" style="display: none;">
        <h4>1.2.1. Header 参数(POST时必须)</h3>
        <table>
            <thead>
                <tr>
                    <th>参数名</th>
                    <th>必选</th>
                    <th>类型/参数值</th>
                    <th>说明</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Content-Type</td>
                    <td>是</td>
                    <td>application/json</td>
                    <td>POST JSON</td>
                </tr>
            </tbody>
        </table>

        <h4>1.2.2. Body 参数(POST时必须)</h3>
        <table>
            <thead>
                <tr>
                    <th>参数名</th>
                    <th>必选</th>
                    <th>类型</th>
                    <th>限制条件</th>
                    <th>说明</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>statement</td>
                    <td>是</td>
                    <td>string</td>
                    <td>1 &lt; 字节长度 &lt; 65535</td>
                    <td>标注语句</td>
                </tr>
            </tbody>
        </table>
    </div>

    <h3>1.3. 请求示例 <button class="round-button" onclick="toggleCodeBlock(this, 'req1')">+</button></h3>
    <div id="req1" style="display: none;">
    <pre><code>
        POST /tag HTTP/1.1
        {
            "statement": "我大抵是病了，要调节血糖，吃些盐酸二甲双胍，或许再吃些奥利司他减减肥"
        }
        //或者
        GET /tag?statement=我大抵是病了，要调节血糖，吃些盐酸二甲双胍，或许再吃些奥利司他减减肥
    </code></pre>
    </div>

    <h3>1.4. 返回示例 <button class="round-button" onclick="toggleCodeBlock(this, 'resp1')">+</button></h3>
    <div id="resp1" style="display: none;">
    <pre><code>{
    "code": 1,  // 1：成功，其他：失败, 全部接口均返回此格式
    "msg": "",  // 错误信息
    "result": {
        "奥利司他": {
            "keyword": "奥利司他",  // 关键词
            "positions": [
                {
                    "start": 26,    // 关键词在语句中的起始位置
                    "end": 29       // 关键词在语句中的结束位置
                }
            ],
            "dictwords": {          // 关键词对应的字典名称及其中的词条列表
                "namecn": [         
                    {
                        "Dict": "namecn",           // 字典名称
                        "word": "奥利司他胶囊",      //  词条
                        "index": [                  //  词条对应的索引词列表
                            "奥利司他",
                            "奥利司他胶囊"
                        ],
                        "data": {                   //  词条数据
                            "categoryId": 19344,
                            "categoryType": "西药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 0
                        }
                    },
                    {
                        "Dict": "namecn",
                        "word": "奥利司他",
                        "index": [
                            "奥利司他"
                        ],
                        "data": {
                            "categoryId": 32832,
                            "categoryType": "原料药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 2
                        }
                    },
                    {
                        "Dict": "namecn",
                        "word": "奥利司他片",
                        "index": [
                            "奥利司他",
                            "奥利司他片"
                        ],
                        "data": {
                            "categoryId": 32833,
                            "categoryType": "西药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 0
                        }
                    }
                ]
            }
        },
        "盐酸": {
            "keyword": "盐酸",
            "positions": [
                {
                    "start": 14,
                    "end": 15
                }
            ],
            "dictwords": {
                "namecn": [
                    {
                        "Dict": "namecn",
                        "word": "盐酸",
                        "index": [
                            "盐酸"
                        ],
                        "data": {
                            "categoryId": 23093,
                            "categoryType": "原料药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 2
                        }
                    }
                ]
            }
        },
        "盐酸二甲双胍": {
            "keyword": "盐酸二甲双胍",
            "positions": [
                {
                    "start": 14,
                    "end": 19
                }
            ],
            "dictwords": {
                "namecn": [
                    {
                        "Dict": "namecn",
                        "word": "盐酸二甲双胍片",
                        "index": [
                            "盐酸二甲双胍",
                            "盐酸二甲双胍片"
                        ],
                        "data": {
                            "categoryId": 975,
                            "categoryType": "西药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 2
                        }
                    },
                    {
                        "Dict": "namecn",
                        "word": "盐酸二甲双胍肠溶片",
                        "index": [
                            "盐酸二甲双胍",
                            "盐酸二甲双胍肠溶片"
                        ],
                        "data": {
                            "categoryId": 10019,
                            "categoryType": "西药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 2
                        }
                    },
                    {
                        "Dict": "namecn",
                        "word": "盐酸二甲双胍缓释片",
                        "index": [
                            "盐酸二甲双胍",
                            "盐酸二甲双胍缓释片"
                        ],
                        "data": {
                            "categoryId": 10508,
                            "categoryType": "西药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 1
                        }
                    },
                    {
                        "Dict": "namecn",
                        "word": "盐酸二甲双胍胶囊",
                        "index": [
                            "盐酸二甲双胍",
                            "盐酸二甲双胍胶囊"
                        ],
                        "data": {
                            "categoryId": 12263,
                            "categoryType": "西药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 2
                        }
                    },
                    {
                        "Dict": "namecn",
                        "word": "盐酸二甲双胍肠溶胶囊",
                        "index": [
                            "盐酸二甲双胍",
                            "盐酸二甲双胍肠溶胶囊"
                        ],
                        "data": {
                            "categoryId": 18175,
                            "categoryType": "西药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 2
                        }
                    },
                    {
                        "Dict": "namecn",
                        "word": "盐酸二甲双胍缓释胶囊",
                        "index": [
                            "盐酸二甲双胍",
                            "盐酸二甲双胍缓释胶囊"
                        ],
                        "data": {
                            "categoryId": 18178,
                            "categoryType": "西药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 2
                        }
                    },
                    {
                        "Dict": "namecn",
                        "word": "盐酸二甲双胍",
                        "index": [
                            "盐酸二甲双胍"
                        ],
                        "data": {
                            "categoryId": 22501,
                            "categoryType": "原料药",
                            "isControl": false,
                            "isHighRisk": false,
                            "medicineType": 2
                        }
                    }
                ]
            }
        },
        "调节血糖": {
            "keyword": "调节血糖",
            "positions": [
                {
                    "start": 8,
                    "end": 11
                }
            ],
            "dictwords": {
                "category": [
                    {
                        "Dict": "category",
                        "word": "调节血糖",
                        "index": [
                            "调节血糖"
                        ],
                        "data": {
                            "categoryId": 32125,
                            "categoryType": "保健品"
                        }
                    }
                ]
            }
        }
    },
    "micros": 189       // 接口耗时，单位微秒
    }</code></pre>
    </div>
</div>

<h2>2. 更新字典接口 <button class="round-button" onclick="toggleCodeBlock(this, 'api2')">+</button></h1>
<div id="api2" style="display: none;">
    <h3>2.1. 接口描述 <button class="round-button" onclick="toggleCodeBlock(this, 'desc2')">-</button></h3>
    <div id="desc2">
        <ul>
            <li>请求地址：<strong>/put</strong></li>
            <li>请求方式: <strong>POST</strong></li>
            <li>返回数据类型：<strong>application/json</strong></li>
            <li>用途：上传一份字典JSON文件，文件名作为字典名称，每行的JSON Object作为一条字典词条</li>
        </ul>
    </div>

    <h3>2.2. 请求参数 <button class="round-button" onclick="toggleCodeBlock(this, 'params2')">+</button></h3>
    <div id="params2" style="display: none;">
        <h4>2.2.1. Header</h3>
        <table>
            <thead>
                <tr>
                    <th>参数名</th>
                    <th>必选</th>
                    <th>类型/参数值</th>
                    <th>说明</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Content-Type</td>
                    <td>是</td>
                    <td>multipart/form-data</td>
                    <td>文件上传</td>
                </tr>
            </tbody>
        </table>

        <h4>1.2.2. Body 参数</h3>
        <table>
            <thead>
                <tr>
                    <th>参数名</th>
                    <th>必选</th>
                    <th>类型</th>
                    <th>限制条件</th>
                    <th>说明</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>file</td>
                    <td>是</td>
                    <td>file</td>
                    <td>不限制</td>
                    <td>字典文件</td>
                </tr>
            </tbody>
        </table>
    </div>    

    <h3>2.3. 字典文件 <button class="round-button" onclick="toggleCodeBlock(this, 'dict')">+</button></h3>
    <div id="dict" style="display: none;">
        <p>字典文件格式为JSON，名称为: {dictName}.json, 每行为一个完整的词条，格式如下：</p>
        <ul>
            <li>word: 字符串，词条名称</li>
            <li>index: 字符串列表，词条索引列表</li>
            <li>data: 自定义JSON Object，词条数据,</li>
        </ul>
        <pre><code>
            [
                {"word":"骨科用药","index":["骨科用药", "骨科"],"data":{"categoryId":44,"categoryType":"西药"}},
                {"word":"合成抗菌","index":["合成抗菌"],"data":{"categoryId":80,"categoryType":"西药"}},
                {"word":"磺胺增效药","index":["磺胺增效药", "磺胺"],"data":{"categoryId":81,"categoryType":"西药"}}
            ]
        </code></pre>
    </div>
</div>


<h2>3. 重构字典索引树 <button class="round-button" onclick="toggleCodeBlock(this, 'api3')">+</button></h1>
<div id="api3" style="display: none;">
    <h3>3.1. 接口描述 <button class="round-button" onclick="toggleCodeBlock(this, 'desc3')">-</button></h3>
    <div id="desc3">
        <ul>
            <li>请求地址：<strong>/reload</strong></li>
            <li>请求方式: <strong>POST/GET</strong></li>
            <li>返回数据类型：<strong>application/json</strong></li>
            <li>用途：无参，根据程序字典目录下的全部字典文件，构建词条索引的前缀树，用于标注时检索</li>
        </ul>
    </div>
</div>

<h2>4. 索引树字典文件详情 <button class="round-button" onclick="toggleCodeBlock(this, 'api4')">+</button></h1>
<div id="api4" style="display: none;">
    <h3>4.1. 接口描述 <button class="round-button" onclick="toggleCodeBlock(this, 'desc4')">-</button></h3>
    <div id="desc4">
        <ul>
            <li>请求地址：<strong>/info</strong></li>
            <li>请求方式: <strong>POST/GET</strong></li>
            <li>返回数据类型：<strong>application/json</strong></li>
            <li>用途：无参，查看上次构建索引树时用到的字典文件及词条数</li>
        </ul>
    </div>
</div>
    

    <script>
        function toggleCodeBlock(btn, blockId) {
            var codeBlock = document.getElementById(blockId);
            if (codeBlock.style.display === "none") {
                codeBlock.style.display = "block";
                btn.innerText = "-";
            } else {
                codeBlock.style.display = "none";
                btn.innerText = "+";
            }
        }
    </script>    

</body>
</html>
